<template>
    <SysDialog :title="dialog.title" :visible="dialog.visible" :width="dialog.width" :height="dialog.height"
        @onClose="onClose" @onConfirm="commit">
        <template v-slot:content>
            <el-form :model="addModel" ref="addFormRef" label-width="90px" :inline="false" size="default">
                <el-row :gutter="20">
                    <el-col :span="8" :offset="0">
                        <el-form-item prop="yingXiaoHuoDongMingCheng" label="营销活动名称">
                            <el-input v-model="addModel.yingXiaoHuoDongMingCheng"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" :offset="0">
                        <el-form-item prop="diDian" label="地点">
                            <el-input v-model="addModel.diDian"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8" :offset="0">
                        <el-form-item prop="date" label="时间">
                              <el-date-picker v-model="addModel.date" type="date"  placeholder="请选择日期"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" :offset="0">
                    </el-col>
                </el-row>
            </el-form>
        </template>
    </SysDialog>
</template>

<script setup lang="ts">

import SysDialog from '@/components/SysDialog.vue'
import useDialog from '@/hooks/useDialog';
import { nextTick, reactive, ref } from 'vue';
import { ElMessage, FormInstance } from 'element-plus';
import { addUserApi, editUserApi, getListApi } from '@/api/qx';
import { EditType, Title } from '@/type/BaseType';
import { QxModel } from '@/api/qx/QxModel';
const { dialog, onClose, onConfirm, onShow } = useDialog()
const show = (type: string, row?: QxModel) => {
    type == EditType.ADD ? dialog.title = Title.ADD : dialog.title = Title.EDIT
    dialog.height = 500
    dialog.width = 1000
    dialog.visible = true
    if (row) {
        nextTick(() => {
            Object.assign(addModel, row)
        })
    }
    addFormRef.value?.resetFields()
    addModel.type = type;
};
defineExpose({
    show
})
const addModel = reactive<QxModel>({
    type: '',
    id: '',
    yingXiaoHuoDongMingCheng: '',
    diDian: '',
    date: '',

})

const addFormRef = ref<FormInstance>()

const emists = defineEmits(['onFresh'])


const commit = () => {
    addFormRef.value?.validate(async (valid) => {
        if (valid) {
            let res = null;
            if (addModel.type == EditType.ADD) {
                res = await addUserApi(addModel);
            } else {
                res = await editUserApi(addModel);
            }
            console.log(res)
            if (res && res.code == 200) {
                ElMessage.success(res.msg)
                emists('onFresh')
                onClose()
            }
        }
    })
}
</script>
<style scoped></style>